
#include "def.h"
#include "jump2App.h"
#include "usart.h"
#include "stdio.h"
#include "string.h"
#include "delay.h"
typedef void (*pFunction)(void);

void jump(uint32_t addr)
{
    uint32_t jumpAddress;
    pFunction JumpToApplication;
    if (((*(__IO uint32_t *)addr) & 0x2FFE0000) == 0x20000000)
    {
        jumpAddress = *(uint32_t *)(addr + 4);
        JumpToApplication = (pFunction)jumpAddress;
        __set_MSP(*(uint32_t *)addr);
        JumpToApplication();
    }
}
//这里跳转比较特殊，因为M0没有中断向量表跳转，所以要通过下面这种方式来特殊处理
//即先将中断向量表拷贝到RAM 0x2000000位置。然后再将中断向量设置从ram启动
//再跳转至APP
void jump2APP(void)
{
    if (((*(__IO uint32_t *)APP_FLASH_ADDRESS) & 0x2FFE0000) != 0x20000000)
    {
        return;
    }
    usart_deinit();
    delay_us(100);
    memcpy((void *)0x20000000, (void *)APP_FLASH_ADDRESS, 0x100);
    //delay_ms(100);
    SYSCFG->CFGR1 |= 0x03;
    jump(APP_FLASH_ADDRESS);
}
